package com.seven.webhook.simple.model.enm;


import com.baomidou.mybatisplus.annotation.IEnum;
import com.seven.webhook.utils.json.BaseJsonEnum;
import lombok.Getter;

/**
 * CPU使用率、内存使用率、整体磁盘平均使用率
 */
@Getter
public enum BaseIndexEnum implements BaseJsonEnum, IEnum<Integer> {
    CPU_USAGE(0, 9100, "CPU使用率",
            "100 - (avg(rate(node_cpu_seconds_total{instance=~\"$ip.*\",mode=\"idle\"}[2m]))by(instance) * 100)"),
    MEMORY_USAGE(1, 9100, "内存使用率",
            "(1 - (node_memory_MemAvailable_bytes{instance=~\"$ip.*\"} / (node_memory_MemTotal_bytes{instance=~\"ip.*\"})))* 100"),
    PARTITION_USAGE(2, 9100, "分区使用率",
            "max((node_filesystem_size_bytes{instance=~\"$ip.*\",job=~\"node exporter\",fstype=~\"ext.?|xfs\"}-node_filesystem_free_bytes{instance=~\"$ip.*\",job=~\"node exporter\",fstype=~\"ext.?|xfs\"}) *100/(node_filesystem_avail_bytes {instance=~\"$ip.*\",job=~\"node exporter\",fstype=~\"ext.?|xfs\"}+(node_filesystem_size_bytes{instance=~\"$ip.*\",job=~\"node exporter\",fstype=~\"ext.?|xfs\"}-node_filesystem_free_bytes{instance=~\"$ip.*\",job=~\"node exporter\",fstype=~\"ext.?|xfs\"})))by(instance)"),
    ;

    BaseIndexEnum(Integer value, Integer port, String des, String expr) {
        this.value = value;
        this.des = des;
        this.expr = expr;
        this.port = port;
    }

    private Integer value;
    private Integer port;
    private String des;
    private String expr;


    public String getExpr(String ip) {
        return expr.replace("$ip", ip);
    }

    @Override
    public Integer getValue() {
        return value;
    }

    @Override
    public String getCode() {
        return this.name();
    }

    @Override
    public String getDes() {
        return des;
    }
}
